package com.ruoyi.ade.controller;

import com.ruoyi.ade.domain.AdeKnowledgeBase;
import com.ruoyi.ade.llm.model.Ade;
import com.ruoyi.ade.llm.model.AdeRecognizeConfig;
import com.ruoyi.ade.llm.model.AdeWithKnowledge;
import com.ruoyi.ade.llm.service.IAdeService;
import com.ruoyi.ade.mapper.AdeKnowledgeBaseMapper;
import com.ruoyi.ade.model.AdePromptDebugRequest;
import com.ruoyi.ade.model.AdePromptExploreRequest;
import com.ruoyi.ade.model.AdeRecognitionRequest;
import com.ruoyi.ade.service.IAdeLlmExecuteService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ADE 识别服务
 */
@RestController
@RequestMapping("/ade/recognition")
public class AdeRecognitionController {

    @Autowired
    private IAdeLlmExecuteService adeLlmExecuteService;

    @Anonymous
    @PostMapping
    public AjaxResult recognize(@RequestBody AdeRecognitionRequest request){
        try {
            AdeWithKnowledge result = adeLlmExecuteService.recognizeWithKnowledge(request);
            return AjaxResult.success(result);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    @Anonymous
    @PostMapping("/explore")
    public AjaxResult recognizeByPrompt(@RequestBody AdeRecognitionRequest request){
        try {
            AdeWithKnowledge result = adeLlmExecuteService.recognizeWithKnowledge(request);
            return AjaxResult.success(result);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    @Anonymous
    @PostMapping("/debug")
    public AjaxResult debugPrompt(@RequestBody AdePromptDebugRequest request){
        return  AjaxResult.success(adeLlmExecuteService.recognize(request.getLlmModel(),request.getSystemPrompt(),request.getUserPrompt()));
    }

}
